﻿using System;

using NHibernate;
using NHibernate.Cfg;

namespace NHibTest.DBTask.MySQL5
{
	/// <summary>
	/// NHibernate 帮助类
	/// </summary>
	internal sealed class NHibernateHelper
	{
		/// <summary>
		/// 会话工厂
		/// </summary>
		private static readonly ISessionFactory _sessionFactory;

		#region 类构造器
		/// <summary>
		/// 类静态构造器
		/// </summary>
		static NHibernateHelper()
		{
			NHibernateHelper._sessionFactory = new Configuration().Configure().BuildSessionFactory();
		}
		#endregion

		/// <summary>
		/// 创建 NHibernate 会话
		/// </summary>
		/// <returns></returns>
		public static ISession CreateSession()
		{
			return NHibernateHelper._sessionFactory.OpenSession();
		}
	}
}
